<template>
    <base-dialog title="添加附件"  v-bind="$attrs" v-on="$listeners">
        <el-form ref="elForm" :model="form" label-width="80px" :rules="rules">
            <el-form-item label="附件" prop="files">
                <my-upload-file v-model="form.files"  previewOrDownload="download"></my-upload-file>
            </el-form-item>
        </el-form>
        <template slot="footer">
            <el-button @click="close">取 消</el-button>
            <el-button type="primary" @click="submitForm()">提 交</el-button>
        </template>
    </base-dialog>
</template>
<script>

    import schoolDocuments from "@/api/officialDocument/schoolDocuments/index"
    import BaseDialog from "../../../Common/BaseDialog";
    import MyUploadFile from "../../../Common/MyUploadFile";
    import eventBus from "../../../../utils/eventBus";
    export default {
        name:"UploadDialog",
        components: {MyUploadFile, BaseDialog},
        props:["id"],
        data(){
            return{
                form:{
                    id:this.id,
                    files:undefined
                },
                rules: {
                    files: [
                        {
                            required: true,
                            message: "请上传附件",
                            trigger: "change"
                        }
                    ],
                },
            }
        },
        methods:{
            close() {
                this.$emit('update:visible', false)
            },
            submitForm(){
                console.log(this.form)
                this.$refs['elForm'].validate(valid => {
                    if (!valid) return
                    this.$confirm("确认上传附件，上传后将不可删除, 是否继续?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning"
                    }).then(() => {
                        schoolDocuments.getDocumentUpload(this.form.id,{files:this.form.files}).then(res=>{
                            this.msgSuccess(res.msg)
                            eventBus.$emit("reloadAttachemnts")
                            this.close()
                        })
                    });
                })
            }
        }
    }
</script>
